package com.csun.cmny.provider.service.impl;

import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.DmcRfidReaderGroupBindMapper;
import com.csun.cmny.provider.dao.DmcRfidReaderLocationMapper;
import com.csun.cmny.provider.model.domain.DmcRfidReaderGroupBind;
import com.csun.cmny.provider.model.dto.device.DevicePageQuery;
import com.csun.cmny.provider.model.enums.device.DmcDeviceTypeEnum;
import com.csun.cmny.provider.model.vo.rfid.DmcRfidReaderVo;
import com.csun.cmny.provider.service.DmcRfidReaderGroupBindService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-08-22 15:01
 * @Description: the class dmc rfid reader group bind service impl
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DmcRfidReaderGroupBindServiceImpl extends BaseService<DmcRfidReaderGroupBind>
        implements DmcRfidReaderGroupBindService {

    @Resource
    private DmcRfidReaderLocationMapper dmcRfidReaderLocationMapper;
    @Resource
    private DmcRfidReaderGroupBindMapper dmcRfidReaderGroupBindMapper;

    /**
     * query rfid reader not bind rfid reader group
     * <p>
     * the rfid reader bind location
     *
     * @param groupId the group id
     *
     * @return the list
     */
    @Override
    public List<DmcRfidReaderVo> queryNotBindRfidReader(Long groupId) {

        DevicePageQuery devicePageQuery = new DevicePageQuery();
        devicePageQuery.setGroupId(groupId);
        devicePageQuery.setPageSize(1000);
        devicePageQuery.setDeviceType(DmcDeviceTypeEnum.RFID_READER.getIndex());

        return dmcRfidReaderLocationMapper.queryNotBindRfidReader(devicePageQuery);
    }

    /**
     * check rfid reader bind rfid reader group by rfid reader id
     *
     * @param deviceId rfid reader id
     *
     * @return true-未绑定 false-已经绑定
     */
    @Override
    public boolean checkRfidReaderBindGroupById(Long deviceId) {

        DmcRfidReaderGroupBind dmcRfidReaderGroupBind = new DmcRfidReaderGroupBind();
        dmcRfidReaderGroupBind.setRfidReaderId(deviceId);
        int count = dmcRfidReaderGroupBindMapper.selectCount(dmcRfidReaderGroupBind);

        return count < 1;
    }

}
